<?php

namespace Admin\Controller;

/** 
 * 敏感词管理
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

class SensitiveController extends BaseManageController 
{

	protected $modelName = 'Common/Sensitive';	
	protected $is_del	= true;
	
	public function _before_index()
	{
		$map = array();
        $map['status']  = array('egt',0);
        I('keyword') && $map['keyword']    =   array('like', I('keyword'));
        $this->where = $map;
	}

	/** 
	 * [批量导入]
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	public function import()
	{
		if (IS_POST)
		{
			set_time_limit(0);
			$model = D('Common/Sensitive', 'Service');
			$keywords = explode(',', I('keywords') );
			if (!$keywords)
			{
				$this->error('没有数据');
			}
			foreach ($keywords as $keyword) {
				$data['keyword'] = trim($keyword);
				$data['replace'] = '***';
				$data =$model->create($data);
				if ($data) $model->add($data);
			}
			$this->success('添加成功');
		}
		else
		{
			$this->display();
		}
	}


	public function refresh()
	{
		A('Api/Sensitive', 'Event')->keywordCache();
		$this->success('刷新成功');
	}




}